package com.cn.jdia.db.utils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cn.jdia.db.manager.DBManager4Mysql;

public class ConfigUtils {

	public static final String USER = "dcenter";
	public static final String PASS = "Qd83789951";
	public static final String URL = "jdbc:mysql://172.20.5.179:3306/datacenter?useUnicode=true&characterEncoding=utf-8";

	public static List<Map<String,String>> getAllConfig() {

		DBManager4Mysql db = DBManager4Mysql.createInstance();
		db.connectDB(URL, USER, PASS);
		
		String query="select * from dbconfig";
		ResultSet rs = db.executeQuery(query);
		
		List<Map<String,String>> list=new ArrayList<>();
		Map<String,String> config;
		try {
			while(rs.next()){
				config=new HashMap<>();
				
				config.put("servername", rs.getString("servername"));
				config.put("ip", rs.getString("ip"));
				config.put("port", rs.getString("port"));
				config.put("dbtype", rs.getString("dbtype"));
				config.put("sid", rs.getString("sid"));
				config.put("user", rs.getString("user"));
				config.put("pwd", rs.getString("pwd"));
				config.put("defaultdb", rs.getString("defaultdb"));
				config.put("warn", rs.getString("bak1"));
				
				list.add(config);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		db.closeDB();
		
		return list;
	}
}
